﻿/*------------------------------------------------------------------------

MUTITEXTURERD.HPP v1.0.0

Copyright 楊志賢 CxxlMan, 2014
All Rights Reserved

------------------------------------------------------------------------*/

#if !defined(__MUTITEXTURERD_HPP_Cxxl3D)
#define __MUTITEXTURERD_HPP_Cxxl3D

#include <CXXLLIST.HPP>
#include <Sys\RenderUnit\SYSDDCLASSID.HPP>
#include <Sys\RenderUnit\SysRenderDatagram\TEXTURERD.HPP>
#include <Sys\MATRIX.HPP>
#include <Sys\CSMART_PTR.HPP>

namespace Cxxl3D
{



class ITextureRD_AttrBox:virtual public CxxlMan::cxxlPreserve2
{
  
protected:


  // 儲存容器藉此取得要永續存取的屬性資料
  // 延伸類別須以 virtual 的形式覆寫
  // 並且須呼叫上層類別的此函數
  virtual bool cxxlFASTCALL Ref(CxxlMan::Filter *F)
  {
    if(F != NULL && CxxlMan::cxxlPreserve2::Ref(F))
      return true;
    else
      return false;
  }


  // Constructor
  ITextureRD_AttrBox()
    :cxxlObject(CxxlMan::Spirit_Easy),
    CxxlMan::cxxlPreserve2(ITextureRD_AttrBox_ClassID) // 在建構時指定 ClassID
  {
  }

  // Destructor
  virtual ~ITextureRD_AttrBox(){}

public:

  virtual void cxxlFASTCALL SetTextureRD(const CxxlMan::Smart_Ptr<ITextureRD> &ITextureRD_Arg) = 0;

  virtual void cxxlFASTCALL Get(CxxlMan::Smart_Ptr<ITextureRD> &ITextureRD_Arg) const = 0;

  // 建立 ITextureRD_AttrBox 物件，失敗傳回 NULL  
  static CxxlMan::Smart_Ptr<ITextureRD_AttrBox> cxxlFASTCALL Create()
  {
    return CxxlMan::Preserve2_Cast<ITextureRD_AttrBox>( CxxlMan::cxxlCM_GetElement(ITextureRD_AttrBox_ClassID, IRenderDatagram_Group) );
  }

  friend class CxxlMan::IcxxlStorage;          // Preserve2 元件須加上這個
  friend class CxxlMan::Smart_Ptr<ITextureRD_AttrBox>;  // Preserve2 元件須加上這個
};
                  
// 執行的順序須在 VERTEXRD.HPP 中有貼圖座標的頂點之後
class IMutiTextureRD:public IRenderDatagram
{
  // 這裡須傳回 IRenderDatagram 的 "實作介面"，即被 cxxlCM_GetElement() 叫用的 InterfaceID
  CxxlMan::UNICODE_String cxxlFASTCALL GetRenderDatagramID() const
  {
    return IMutiTextureRD_ClassID;
  }

  // 傳回 IRenderDatagram 的 "實作介面"
  virtual void *cxxlFASTCALL GetDefaultInterface()
  {
    return this;
  }

  virtual CxxlMan::Smart_Ptr<CxxlMan::cxxlList<ITextureRD_AttrBox> > cxxlFASTCALL GetTextureRDList()  const = 0;

protected:


  // 儲存容器藉此取得要永續存取的屬性資料
  // 延伸類別須以 virtual 的形式覆寫
  // 並且須呼叫上層類別的此函數
  virtual bool cxxlFASTCALL Ref(CxxlMan::Filter *F)
  {
    if(F != NULL && CxxlMan::cxxlPreserve2::Ref(F))
      return true;
    else
      return false;
  }


  // Constructor
  IMutiTextureRD()
    :cxxlObject(CxxlMan::Spirit_Easy),
    CxxlMan::cxxlPreserve2(IMutiTextureRD_ClassID) // 在建構時指定 ClassID
  {
  }

  // Destructor
  virtual ~IMutiTextureRD()
  {
  }

public:

  // 依序放入 ITextureRD_AttrBox
  virtual void cxxlFASTCALL PutTexture(const CxxlMan::Smart_Ptr<ITextureRD_AttrBox> &ITextureRD_AttrBox_Arg) = 0;

  // 清除後才可再從頭放入 ITextureRD_AttrBox
  virtual void cxxlFASTCALL Clear() = 0;

  // 建立 IMutiTextureRD 物件，失敗傳回 NULL  
  static CxxlMan::Smart_Ptr<IMutiTextureRD> cxxlFASTCALL Create()
  {
    return CxxlMan::Preserve2_Cast<IMutiTextureRD>( CxxlMan::cxxlCM_GetElement(IMutiTextureRD_ClassID, IRenderDatagram_Group) );;
  }

  friend class IMutiTextureBridge;
  friend class CxxlMan::IcxxlStorage;          // Preserve2 元件須加上這個
  friend class CxxlMan::Smart_Ptr<IMutiTextureRD>;  // Preserve2 元件須加上這個

};


// Render 單元要叫用 IMutiTextureRD 提供給其叫用的功能，須繼承此介面
class IMutiTextureBridge
{
protected:
  // 由 Render 單元叫用，以取得 ITextureRD 資料
  CxxlMan::Smart_Ptr<CxxlMan::cxxlList<ITextureRD_AttrBox> >  cxxlFASTCALL GetTextureRDList(const CxxlMan::Smart_Ptr<IMutiTextureRD> &IMutiTextureRD_Arg) const
  {
    return IMutiTextureRD_Arg->GetTextureRDList();
  }

public:
  IMutiTextureBridge(){}
  ~IMutiTextureBridge(){}

};

}   /* namespace Cxxl3D */
#endif

